#include<iostream>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<vector>
#include<cstring>
#define inf 1<<30
using namespace std;
int edge[][2] =
{
{ 1, 2 },
{ 2, 3 },
{ 3, 4 },
{ 1, 5 },
{ 2, 6 },
{ 3, 7 },
{ 4, 8 },
{ 5, 6 },
{ 6, 7 },
{ 7, 8 },
{ 5, 9 },
{ 6, 10 },
{ 7, 11 },
{ 8, 12 },
{ 9, 10 },
{ 10, 11 },
{ 11, 12 },
{ 9, 13 },
{ 10, 14 },
{ 11, 15 },
{ 12, 16 },
{ 13, 14 },
{ 14, 15 },
{ 15, 16 } };
int tri[][4] =
{
{ 0, 3, 4, 7 },
{ 1, 4, 5, 8 },
{ 2, 5, 6, 9 },
{ 7, 10, 11, 14 },
{ 8, 11, 12, 15 },
{ 9, 12, 13, 16 },
{ 14, 17, 18, 21 },
{ 15, 18, 19, 22 },
{ 16, 19, 20, 23 } };
int p[25], idx[25], cnt, sum;
int dp[1 << 12];
int cal(int state, int e)
{
    int ans = 0, t = 0;
    for (int i = 0; i < 9; i++)
    {
        bool flag = 0;
        for (int j = 0; j < 4; j++)
            if (e == tri[i][j])
            {
                flag = true;
                break;
            }
        if (flag)
        {
            t++;
            for (int j = 0; j < 4; j++)
            {
            	if (!(p[tri[i][j]] & state || e == tri[i][j]))
                {
                    ans--;
                    break;
                }
            }
            ans++;
        }
        if (t == 2)
            break;
    }
    return ans;
}
int dfs(int state, int now, int last)
{
    if (dp[now] != -inf)
        return dp[now];
    int ans = -inf;
    for (int i = 0; i < cnt; i++)
    {
        if (!(now & p[i]))
        {
            int tem = cal(state, idx[i]);
            int tt = last - dfs(state | p[idx[i]], now | p[i], last - tem);
            ans = max(ans, tt);
        }
    }
    return dp[now] = ans;
}
int main()
{
    int T;
    scanf("%d",&T);
    p[0] = 1;
    bool vis[25];
    for (int i = 1; i <= 24; i++)
        p[i] = p[i - 1] * 2;
    for (int cas = 1; cas <= T; cas++)
    {
        int n, m1 = 0, m2 = 0, side = 0, a, b, tem;
        int state = 0;
        memset(vis, 0, sizeof(vis));
        scanf("%d", &n);
        for (int i = 1; i <= n; i++)
        {
            scanf("%d%d", &a, &b);
            if (a > b)
                swap(a, b);
            for (int j = 0; j < 24; j++)
                if (edge[j][0] == a && edge[j][1] == b)
                {
                    tem = cal(state, j);
                    vis[j] = 1;
                    state |= p[j];
                    side == 0 ? m1 += tem : m2 += tem;
                    side = 1 - side;
                    break;
                }
        }
        cnt = 0;
        for (int i = 0; i < 24; i++)
        {
            if (!vis[i])
                idx[cnt++] = i;
        }
        for (int i = 0; i < (1 << cnt); i++)
            dp[i] = -inf;
        dp[(1 << cnt) - 1] = 0;
        tem = dfs(state, 0, 9 - m1 - m2);
        if (side == 0)
        {
            m1 += tem;
            m2 = 9 - m1;
        }
        else
        {
            m2 += tem;
            m1 = 9 - m2;
        }
        printf("Case #%d: %s\n", cas,m1 > m2 ? "Tom200" : "Jerry404");
    }
    return 0;
}
